home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / urt / amiga_extras / rletoqrt / rletoqrt.c < prev   
Encoding:
C/C++ Source or Header  |  1992-12-26  |  2.9 KB  |  123 lines

  1. /*
  2.  * This software is copyrighted as noted below.  It may be freely copied,
  3.  * modified, and redistributed, provided that the copyright notices are 
  4.  * preserved on all copies.
  5.  * 
  6.  * There is no warranty or other guarantee of fitness for this software,
  7.  * it is provided solely "as is".  Bug reports or fixes may be sent
  8.  * to the author, who may or may not act on them as he desires.
  9.  *
  10.  * You may not include this software in a program or other software product
  11.  * without supplying the source, or without informing the end-user that the 
  12.  * source is available for no extra charge.
  13.  *
  14.  * If you modify this software, you should include a notice giving the
  15.  * name of the person performing the modification, the date of modification,
  16.  * and the reason for such modification.
  17.  */
  18. /* 
  19.  * rletoqrt.c - Converts an RLE file into a qrt file.
  20.  * 
  21.  * Author:    Kriton Kyrimis
  22.  * Based on rletogray.c by Michael J. Banks
  23.  */
  24.  
  25. #include <stdio.h>
  26. #include "rle.h"
  27.  
  28. #ifdef USE_STDLIB_H
  29. #include <stdlib.h>
  30. #else
  31.  
  32. #ifdef USE_STRING_H
  33. #include <string.h>
  34. #else
  35. #include <strings.h>
  36. #endif
  37.  
  38. #ifdef VOID_STAR
  39. extern void *malloc(), *calloc();
  40. #else
  41. extern char *malloc(), *calloc();
  42. #endif
  43. extern void free();
  44.  
  45. #endif /* USE_STDLIB_H */
  46.  
  47. /*
  48.  * usage : rletoqrt [-o outfile] [infile]
  49.  *
  50.  *    -o outfile        Specifies ouput file name.
  51.  *    infile            File to split.  If none, uses stdin.
  52.  */
  53.  
  54. void
  55. out(int x, FILE* f)
  56. {
  57.   unsigned char l, h;
  58.  
  59.   l = x & 0xff;
  60.   h = ((x & 0xff00) >> 8) & 0xff;
  61.   fwrite(&l, sizeof(l), 1, f);
  62.   fwrite(&h, sizeof(h), 1, f);
  63. }
  64.  
  65. void
  66. main(argc, argv)
  67. int  argc;
  68. char *argv[];
  69. {
  70.     char       *inpnam = NULL;    /* Input file name. */
  71.     char       *outnam = NULL;    /* Output file name. */
  72.     int     oflag = 0;    /* Output file name prefix flag. */
  73.     register char * cp, * slashp;
  74.     FILE       *outfil;        /* Output file pointer. */
  75.     int     scans, rasts;    /* Number of scan lines. */
  76.     rle_pixel **inprow;        /* Input buffer. */
  77.     int     i, row;
  78.  
  79.     if (! scanargs( argc,argv,
  80.     "% o%-outfile!s infile%s", &oflag, &outnam, &inpnam ))
  81.     exit( -1 );
  82.  
  83.     /* If an input file is specified, open it. Otherwise use stdin. */
  84.  
  85.     rle_dflt_hdr.rle_file = rle_open_f("rletogray", inpnam, "r");
  86.     /* Read header information. */
  87.  
  88.     rle_get_setup( &rle_dflt_hdr );
  89.     scans = rle_dflt_hdr.ymax - rle_dflt_hdr.ymin + 1;
  90.     rasts = rle_dflt_hdr.xmax - rle_dflt_hdr.xmin + 1;
  91.  
  92.     if (!oflag) {
  93.         outfil = stdout;
  94.     }else{
  95.         if (( outfil = fopen(outnam, "w")) == NULL) {
  96.             perror(outnam);
  97.             exit(-1);
  98.         }
  99.     }
  100.  
  101.     /* Allocate input buffer. */
  102.  
  103.     if (rle_row_alloc( &rle_dflt_hdr, &inprow ))
  104.     {
  105.     fprintf(stderr, "rletoqrt: Out of memory.\n");
  106.     exit(-2);
  107.     }
  108.  
  109.     /* Read .rle file, and convert to qrt. */
  110.  
  111.     out(rasts, outfil);
  112.     out(scans, outfil);
  113.  
  114.     for (row=0; (row<scans); row++)
  115.     {
  116.         out(row, outfil);
  117.     rle_getrow( &rle_dflt_hdr, inprow );
  118.     for ( i = 0; i<3; i++ )
  119.         fwrite( inprow[i], 1, rasts, outfil );
  120.     }
  121.     exit(0);
  122. }
  123.